package es.javamyadmin.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.javamyadmin.dao.TablesDAO;
import es.javamyadmin.modelo.Tables;


public class MostrarTablasAjax extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("dentro");
		String text = "<ul>";
		String user = request.getParameter("usuario");
		String pass = request.getParameter("pass");
		String host = request.getParameter("servidor");
		String port = request.getParameter("puerto");
		String database = request.getParameter("bd");
		TablesDAO listaTablas = new TablesDAO();
		Iterator lista = listaTablas.leerTables(user, pass, host, port, database).iterator();
		
		while(lista.hasNext()){
			Tables tablas =  (Tables) lista.next();
			text = text + "<li><a href='/JavaAdmin/jsp/contenido-tablas-bd.jsp?bd="+database + "&tabla="+tablas.getNombreTable() + "'>" + tablas.getNombreTable() + "</a></li>";
		}
		
		
		
		text = text + "</ul>";
	    PrintWriter out = response.getWriter();
		try{
			out.print(text);
		}finally{
			out.close();
		}
	}

}
